from django_redis import get_redis_connection


class MyReids:
    def __init__(self):
        self.redis = get_redis_connection(alias="code")

    def setstr(self, key, value, time):
        return self.redis.setex(key, time, value)

    def getstr(self, key):
        val = self.redis.get(key)
        if val:
            return val.decode("utf-8")
        else:
            return None

    def hotadd(self,key,word):
        return self.redis.zincrby(key,1,word)
    def hotget(self,key,num):
        return self.redis.zrevrange(key,0,num)

    def setstrno(self,key,value):
        return self.redis.set(key,value)

    def delkey(self,key):
        return self.redis.delete(key)

redistoll = MyReids()
